﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNADota.ContentPipeline.Data;
using XNADota.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNADota.UI
{
    public class Label : UIElement
    {
        private LabelSetting _Setting;
        private SpriteInstance _SpriteInstance;
        private Texture2D _Texture;

        public LabelSetting Setting
        {
            get { return _Setting; }
        }

        public Label(Game game, LabelSetting setting):
            base(game)
        {
            PaletteRendererManager manager = SceneManager.Instance.PaletteRendererManager;
            _Setting = setting;

            try
            {
                _Texture = game.Content.Load<Texture2D>(_Setting.TextureFileName);
            }
            catch (System.Exception e)
            {
                XNADotaHelper.AddMissingFile(_Setting.TextureFileName);
                _Texture = game.Content.Load<Texture2D>(XNADotaHelper.DefaultTGA);
            }
            _SpriteInstance = new SpriteInstance(
                _Setting.X, _Setting.Y, _Setting.Width, _Setting.Height,
                _Setting.SX, _Setting.SY, _Setting.SW, _Setting.SH, _Texture,
                manager.GetPaletteRenderer(EPaletteRendererType.Sprite, "AlphaBlend"));

            Visible = true;
        }

        public override void Draw(GameTime gameTime)
        {
            if (Visible)
                SceneManager.Instance.AddIntoRenderQueue(_SpriteInstance);
        }
    }
}
